{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
	<h3 class="pb-3">{$types[$type]}</h3>
	<table class="layui-table">
		<tr>
			<td class="layui-td-gray">应用名称</td>
			<td>
				<input type="text" name="name" value="{$detail.name}" disabled lay-reqText="请输入应用名称" placeholder="请输入应用名称" class="layui-input">
			</td>
		</tr>
        <tr>
			<td class="layui-td-gray">指定用户</td>
			<td><select id="user_id" name="user_id" xm-selected="{$user_id}" xm-select="select1" xm-select-skin="default"></select></td>
		</tr>
        <tr>
			<td class="layui-td-gray">指定部门</td>
			<td><select id="dept_id" name="dept_id" xm-selected="{$dept_id}" xm-select="select2" xm-select-skin="default"></select></td>
		</tr>
        <tr>
			<td class="layui-td-gray">指定岗位</td>
			<td><select id="group_id" name="group_id" xm-selected="{$group_id}" xm-select="select3" xm-select-skin="default"></select></td>
		</tr>
	</table>
	<div class="pt-4">
		<input type="hidden" name="id" value="{$id}">
        <input type="hidden" name="type" value="{$type}">
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	</div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool', 'formSelects'];
	function gouguInit() {
		var form = layui.form,tool=layui.tool,formSelects=layui.formSelects;
		var selected_a = $('#dept_id').attr('xm-selected');
		formSelects.data('select2', 'server', {
			url: '/api/index/get_department_select',
			keyword: selected_a
		});
        var selected_b = $('#group_id').attr('xm-selected');
		formSelects.data('select3', 'server', {
			url: '/xapply/myapp/select?type=post',
			keyword: selected_b
		});
        var selected_c = $('#user_id').attr('xm-selected');
		formSelects.data('select1', 'server', {
			url: '/xapply/myapp/select?type=user',
			keyword: selected_c
		});
		form.on('submit(webform)', function(data){
			let callback = function (e) {
				layer.msg(e.msg);
				if (e.code == 0) {
					setTimeout(function () {
						parent.location.reload();
					}, 1000);					
				}
			}
			tool.post("/xapply/myapp/perm", data.field, callback);
			return false;
		});
		//监听提交
		form.on('submit(webform)', function(data){
			let callback = function (e) {
				layer.msg(e.msg);
				if (e.code == 0) {
					tool.sideClose(1000);
				}
			}
			tool.post("/xapply/myapp/perm", data.field, callback);
			return false;
		});
	}

</script>
{/block}
<!-- /脚本 -->